﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SmartCity.EventHandle.API.Write.Application.Commands;
using SmartCity.EventHandle.Errorcode;
using SmartCity.EventHandle.Infrastructure.Commons;

namespace SmartCity.EventHandle.API.Write.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ManagementController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly ILogger<ManagementController> logger;

        public ManagementController(IMediator mediator,ILogger<ManagementController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 添加应用
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回应用任务</returns>
        [HttpPost]
        public async Task<ApiResult<int>> AddApp(AppCreateCommand request)
        {
            return await mediator.Send(request);
        }
        [HttpPost]
        public async Task<ApiResult<int>> UpdateApp([FromQuery]AppUpdateCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 获取枚举值的列表
        /// </summary>
        /// <returns>返回字典</returns>
        [HttpGet]
        [AllowAnonymous]
        public IActionResult GetEnum()
        {
            //var list = EnumHelper.GetFlowStatus().ToList();
            //return Ok(list);
            var list = EnumHelper.GetEnums<FlowStatus>().ToList();
            return Ok(list);
        }
    }
}
